#include <mytime.h>
#include <printThings.h>
#include <ports.h>

unsigned char locked = 0;
int tim = 0;

unsigned long timerTicks = 0;
unsigned long eticks;

//900000 floppy geht


void timerHandler()
{
    ++timerTicks;
    if(eticks)
        --eticks;
}

void timerWait (unsigned long ticks)
{
    eticks = ticks;

    while (eticks)
    {
        /*do nothing*/
    }
}

void sleepSeconds (unsigned long seconds)
{
    timerWait((unsigned long)100*seconds);
}

void sleepMilliSeconds (unsigned long ms)
{
    timerWait((unsigned long)(ms/10));
}


void setTimerFrequenz(unsigned int frequ){
    unsigned int div = 1193180 / frequ;

    /*sagen wir dem timer dass wir die frequenz aendern wollen*/
    outb(0x43, 0x36);

    /*jetzt setzen wir die frequenz*/
    outb(0x40, (unsigned char)(div & 0xFF)); 
    outb(0x40, (unsigned char)((div>>8) & 0xFF));
}

void sleep(int x) {
    /*int erg = tim + x;
    while(1){
    	if(tim >= erg)
    	return;
    }
    */
    int i = 0;
    for (i = 0; i < 9000; i++) {}
}

